package com.itheima.tanhua.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.itheima.domain.db.UserInfo;
import com.itheima.tanhua.mapper.UserInfoMapper;
import com.itheima.tanhua.service.UserInfoService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @author zsk
 * @create 2022-03-30-15:45
 */
@Service
public class UserInfoServiceImpl implements UserInfoService {

    @Autowired
    private UserInfoMapper userInfoMapper;

    //分页查询用户信息
    @Override
    public Page<UserInfo> findByPage(String name, Integer pageNum, Integer pageSize) {

        //构建查询条件
        LambdaQueryWrapper<UserInfo> wrapper = new LambdaQueryWrapper<>();
        wrapper.like(StringUtils.isNoneEmpty(name),UserInfo::getNickname,name);

        //设置分页条件
        Page<UserInfo> page = new Page<>(pageNum, pageSize);

        //查询
        page = userInfoMapper.selectPage(page,wrapper);

        //返回结果
        return page;
    }
}
